﻿using Core.Formats;
using Core.ReadWriter;
using Core.Tools;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Test
{
    [Serializable]
    public class TestSer
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public int Sex { get; set; }
    }
    public class Test_Class
    {
        public static void Test()
        {
            TestSer ts = new TestSer();

            BinaryFormatter binaryFormatter = new BinaryFormatter();
            EsonFormat jsonFormat = new EsonFormat();

            using (FileStream Ms = new FileStream("D://Test.txt", FileMode.Create, FileAccess.ReadWrite))
            {

                using (StreamWriter SW = new StreamWriter(Ms))
                {
                    jsonFormat.Encode(BaseReadWriter.Create(ts), SW);
                }


                //binaryFormatter.Serialize(Ms, ts);
            }

            var Begin = DateTime.Now;
            for (int i = 0; i < 10000; i++)
            {
                using (FileStream Ms = new FileStream("D://Test.txt", FileMode.Open, FileAccess.ReadWrite))
                {
                    using (StreamReader Sr = new StreamReader(Ms))
                    {
                        TableReadWriter trw = new TableReadWriter();

                        jsonFormat.Decode(Sr.ReadToEnd(), trw);
                    }
                }
            }

            //for (int i = 0; i < 10000; i++)
            //{
            //    using (FileStream Ms = new FileStream("D://Test.txt", FileMode.Open, FileAccess.ReadWrite))
            //    {
            //        binaryFormatter.Deserialize(Ms);
            //    }
            //}

            Console.WriteLine((DateTime.Now - Begin).TotalMilliseconds);
        }
    }
}
